<?php
if (!(defined('IN_IA')))
{
	exit('Access Denied');
}
require EWEI_SHOPV2_PLUGIN . 'commission/core/page_login_mobile.php';

class Unlimited_EweiShopV2Page extends CommissionMobileLoginPage
{

	#订单明细
	public function order()
	{
		global $_W, $_GPC;
      	include $this->template();
	}
	public function order_get_list()
	{
		global $_W, $_GPC;
		$openid = $_W['openid'];
		$uniacid = $_W['uniacid'];
		$pindex = max(1, intval($_GPC['page']));
		$psize = 20;

		$status = trim($_GPC['status']);

		$condition = ' and o.status>=0';

		if ($status != '') {
			$condition = ' and o.status=' . intval($status);
		}

		$condition .= ' and log.openid = :openid ';
		$params[':openid'] = $openid;

		$list = pdo_fetchall('select o.id as oid ,o.ordersn,o.status as ostatus,o.price,o.goodsprice,log.*,o.openid as oopenid from '.tablename('ewei_shop_unlimited_commission').' log left join ' . tablename('ewei_shop_order') . ' o on o.id = log.orderid  where 1 '.$condition.' order by log.id desc',$params);

		if (!empty($list)) {
			foreach ($list as &$row) {


				$row['createtime'] = date('Y-m-d H:i', $row['createtime']);

				if ($row['ostatus'] == 0) {
					$row['statusstr'] = '待付款';
				}
				else if ($row['ostatus'] == 1) {
					$row['statusstr'] = '已付款';
				}
				else if ($row['ostatus'] == 2) {
					$row['statusstr'] = '待收货';
				}
				else {
					if ($row['ostatus'] == 3) {
						$row['statusstr'] = '已完成';
					}else{
						$row['statusstr'] = '已关闭';
					}
				}

				$goods = pdo_fetchall('SELECT og.id,og.goodsid,g.thumb,og.price,og.total,g.title,og.optionname,og.realprice from ' . tablename('ewei_shop_order_goods') . ' og' . ' left join ' . tablename('ewei_shop_goods') . ' g on g.id=og.goodsid  ' . ' where og.orderid=:orderid and og.nocommission=0 and og.uniacid = :uniacid order by og.createtime  desc ', array(':uniacid' => $_W['uniacid'], ':orderid' => $row['oid']));
				$goods = set_medias($goods, 'thumb');

				$row['order_goods'] = set_medias($goods, 'thumb');

				$row['buyer'] = m('member')->getMember($row['oopenid']);


			}
			unset($row);
		}

		$total = pdo_fetchcolumn('select count(*) from  '.tablename('ewei_shop_unlimited_commission').' log left join '.tablename('ewei_shop_order').' o on o.id = log.orderid where 1 ' . $condition,$params);
		show_json(1, array(
			'list' => $list,
			'pagesize' => $psize,
			'total' => $total
		));
	}
}
?>